<template>
  <div id="messagePage">
    <el-form ref="form" :model="form" label-width="80px" style="text-align: left">
      <el-form-item label="通知标题">
        <el-input v-model="form.title"></el-input>
      </el-form-item>

      <el-form-item label="通知时间">
        <el-date-picker v-model="form.date" type="datetime" placeholder="选择日期时间" class="width1">
        </el-date-picker>
      </el-form-item>

      <el-form-item label="通知内容">
        <el-input type="textarea" v-model="form.content"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">立即创建</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  export default {
    props: {
      addOrRevise: {
        type: String
      },
      mesId: {
        type: Number
      },
      mesDetail: {
        type: Object
      }
    },
    data () {
      return {
        form: {
          title: '',
          content: '',
          date: ''

        }
      }
    },

    created() {

      for (let i in this.mesDetail) {
        for (let j in this.form) {
          if (i == j) {
            this.form[j] = this.mesDetail[i];
          }
        }
      }
    },
    methods: {
      onSubmit() {
        if (this.addOrRevise == 'revise') {
          this.form.id = this.mesId;
          this.getMessageList();
        }
        if (this.addOrRevise == 'add') {
          if (this.form.id) {
            delete this.form.id
          }
          this.getMessageList();
        }
      },
      getMessageList() {
        this.form.date = Date.parse(this.form.date);
        this.$api.saveMessage(this.form).then(res => {
          if (res.code == '000000') {
            console.log(res.data);
            this.$message({
              type: 'success',
              message: '操作成功'
            });
            this.form.title = '';
            this.form.content = '';
            this.form.date = ''
            this.$emit('isSuccess', 'success')
          }
        })
      }
    },
    watch: {
      mesId(mes) {
        console.log(mes)
      },
      mesDetail(mes) {
        for (let i in this.mesDetail) {
          for (let j in this.form) {
            if (i == j) {
              this.form[j] = this.mesDetail[i];

            }
          }
        }
      }
    }


  }
</script>

<style lang="less">

</style>
